﻿using System;
using System.Diagnostics;

namespace PmfWeb.Core.Attributes
{
    ///<summary>
    /// 字段特性
    ///</summary>
    [AttributeUsage(AttributeTargets.Property)]
    public class FieldAttribute: System.Attribute
    {
        private string _fieldName;
        private bool _isPrimary;
        /// <summary>
        /// 是否主键
        /// </summary>
        public virtual bool IsPrimary
        {
            [DebuggerStepThrough]
            get { return _isPrimary; }
            [DebuggerStepThrough]
            set { _isPrimary = value; }
        }


        public FieldAttribute(){}

        /// <summary>
        /// 构造器
        /// </summary>
        /// <param name="fieldname">表名</param>
        /// <param name="description">字段说明</param>
        /// <param name="fieldType">字段类型</param>
        /// <param name="max">最大长度</param>
        /// <param name="min">最小长度</param>
        public FieldAttribute(string fieldname, string description, string fieldType, int max, int min, string defaultValue)
        {
            _fieldName = fieldname;
            _fieldType = fieldType;
            _description = description;
            _max = max;
            _min = min;
            _defaultvalue = defaultValue;
        }
        /// <summary>
        /// 构造器
        /// </summary>
        /// <param name="fieldName">表名</param>
        /// <param name="min">最小长度</param>
        /// <param name="max">最大长度</param>
        public FieldAttribute(string fieldName, int min, int max)
        {
            _fieldName = fieldName;
            _fieldType = "varchar";
            _description = "";
            _max = max;
            _min = min;
            _defaultvalue = "";
        }

        /// <summary>
        /// 列名
        /// </summary>
        public virtual string FieldName
        {
            [DebuggerStepThrough]
            get { return _fieldName; }
            [DebuggerStepThrough]
            set { _fieldName = value; }
        }
        /// <summary>
        /// 列说明
        /// </summary>
        public virtual string Description
        {
            [DebuggerStepThrough]
            get { return _description; }
            [DebuggerStepThrough]
            set { _description = value; }
        }
        /// <summary>
        /// 列类型
        /// </summary>
        public virtual string FieldType
        {
            [DebuggerStepThrough]
            get { return _fieldType; }
            [DebuggerStepThrough]
            set { _fieldType = value; }
        }
        /// <summary>
        /// 列默认值
        /// </summary>
        public virtual string DefaultValue
        {
            [DebuggerStepThrough]
            get { return _defaultvalue; }
            [DebuggerStepThrough]
            set { _defaultvalue = value; }
        }
        /// <summary>
        /// 列最大长度
        /// </summary>
        public virtual int Max
        {
            [DebuggerStepThrough]
            get { return _max; }
            [DebuggerStepThrough]
            set { _max = value; }
        }
        /// <summary>
        /// 列最小长度
        /// </summary>
        public virtual int Min
        {
            [DebuggerStepThrough]
            get { return _min; }
            [DebuggerStepThrough]
            set { _min = value; }
        }

        private string _defaultvalue;
        private string _description;
        private string _fieldType;
        private int _max;
        private int _min;
    }
}
